﻿#ifndef SALEWIDGET_H
#define SALEWIDGET_H

#include <QWidget>
#include <QPushButton>
#include <QTableWidget>
#include "salemodel.h"
#include <QDebug>
#include "excelbase.h"
#include "qprintermanager.h"
#include "userpicker.h"
#include "productpicker.h"
#include "dingdanpicker.h"
#include "dingdan.h"
#include "dingdanservice.h"
#include "salecalculatewidget.h"
#include "dingdanimportwidget.h"
#include "productservice.h"

namespace Ui {
class SaleWidget;
}

class SaleWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SaleWidget(QWidget *parent = nullptr);
    ~SaleWidget();
    QPushButton *btnImport;//导入

    QPushButton *btnPrint;//打印
    QPushButton *btnExport;//导出
    QPushButton *btnPreview;//预览

    QPushButton *btnPrice;//价格
    QPushButton *btnSubmit;//结算

    SaleModel *model;

    Dingdan dingdan;

    void setWidgetType(Dingdan::DingdanType widgetType);

    void showMessage(QString message);

    void setSelectionRow();

    void clear();

    void refreshTotalState();

    void initWithDingdan(Dingdan &dingdan);

private slots:
    void showMenu(const QPoint point);

    void on_pushButtonImport_clicked();

    void on_pushButtonExport_clicked();

    void on_pushButtonNew_clicked();

    void on_pushButtonPrint_clicked();

    void on_pushButtonPreview_clicked();

    void on_pushButtonOpen_clicked();

    void on_comboBox_currentIndexChanged(int index);

    void on_pushButtonSave_clicked();

    void on_pushButtonDelete_clicked();

    void on_pushButtonSubmit_clicked();

    void on_pushButtonPrice_clicked();

private:
    Ui::SaleWidget *ui;

    QScopedPointer<ExcelBase> m_xls;
    QPrinterManager printManager;

    QMenu menu;
    int curRow;
    UserRelation *relation;

    UserPicker userPicker;
    ProductPicker productPicker;
    DingdanPicker dingdanPicker;
    SaleCalculateWidget saleCalculateWidget;
    DingdanImportWidget dingdanImportWidget;
    DingdanService dingdanService;
    ProductService productService;

    int totalCount;
    double totalMoney;

    QPalette blackPalette;
    QPalette redPalette;

    Dingdan::DingdanType widgetType;
};

#endif // SALEWIDGET_H
